package com.example.photography.fragment.community;

import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.photography.R;
import com.example.photography.adapter.ViewPagerAdapter;
import com.example.photography.common.BaseFragment;
import com.example.photography.fragment.home.Home_scenery;
import com.example.photography.util.UIUtils;
import com.google.android.material.tabs.TabLayout;
import com.loopj.android.http.RequestParams;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static androidx.constraintlayout.motion.widget.MotionScene.TAG;

public class Community_Appoint extends BaseFragment {
    @BindView(R.id.et_search)
    EditText etSearch;
    @BindView(R.id.tb_title)
    TabLayout tbTitle;
    @BindView(R.id.tv_publish)
    TextView tvPublish;
    @BindView(R.id.vp_invest)
    ViewPager vpInvest;
    private ViewPagerAdapter viewPagerAdapter;
    private List<Fragment> fragmentList = new ArrayList<>();

    @Override
    protected RequestParams getParams() {
        return null;
    }

    @Override
    protected String getUrl() {
        return null;
    }

    @Override
    protected void initData(String content) {
        //1. 加载多个不同的Fragment
        initFragments();
        //2.ViewPager设置多个Fragment的显示
        viewPagerAdapter = new ViewPagerAdapter(getChildFragmentManager(), UIUtils.getStringArr(R.array.appoint_tab),fragmentList);
        vpInvest.setAdapter(viewPagerAdapter);

        vpInvest.setCurrentItem(0);//设置viewpager的初始化位置
        tbTitle.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                Log.i(TAG, "onTabSelected:" + tab.getText());
                vpInvest.setCurrentItem(tab.getPosition());
                View view = tab.getCustomView();
                if (null == view) {
                    tab.setCustomView(R.layout.tab_layout_text);
                }
                TextView textView = tab.getCustomView().findViewById(android.R.id.text1);
                textView.setTextAppearance(getActivity(), R.style.TabLayoutTextSize_select);
                textView.setTextSize(13);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                tab.setCustomView(null);
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        //3.将TabLayout绑定ViewPager
        tbTitle.setupWithViewPager(vpInvest);
    }
    private void initFragments() {
        //添加到集合中
        fragmentList.add(new Appoint_Recently());
        fragmentList.add(new Appoint_Recently());

    }
    @Override
    public int getLayoutId() {
        return R.layout.fragment_com_appoint;
    }
}
